Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
    ''' <summary>
    ''' Controller class for Games
    ''' </summary>
		<System.ComponentModel.DataObject()> Public Partial Class GamesController
    
        ' Preload our schema..
        Dim thisSchemaLoad As Games = New Games()
        Private strUserName As String = String.Empty
        Protected ReadOnly Property UserName() As String
            Get
				If strUserName.Length = 0 Then
		        
    				If Not System.Web.HttpContext.Current Is Nothing Then
						strUserName = System.Web.HttpContext.Current.User.Identity.Name
					Else
		        		strUserName = System.Threading.Thread.CurrentPrincipal.Identity.Name
					End If
					Return strUserName
				End If
				Return strUserName
			End Get
        End Property
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchAll() As GamesCollection
        
            Dim coll As GamesCollection = New GamesCollection()
            Dim qry As Query = New Query(Games.Schema)
            coll.LoadAndCloseReader(qry.ExecuteReader())
            Return coll
            
        End Function
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchByID(ByVal Id As Object) As GamesCollection 
        
            Dim coll As GamesCollection = New GamesCollection().Where("id", Id).Load()
            Return coll
        
        End Function
        
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchByQuery(ByVal qry As SubSonic.Query) As GamesCollection 
        
            Dim coll As GamesCollection = New GamesCollection()
            coll.LoadAndCloseReader(qry.ExecuteReader())
            Return coll
        
        End Function
        <DataObjectMethod(DataObjectMethodType.Delete, True)> Public Function Delete(ByVal Id As Object) as Boolean
        
            Return (Games.Delete(Id) = 1)
        
        End Function
        <DataObjectMethod(DataObjectMethodType.Delete, False)> Public Function Destroy(ByVal Id As Object) as Boolean
        
            Return (Games.Destroy(Id) = 1)
        
        End Function
        
    	
	    ''' <summary>
	    ''' Inserts a record, can be used with the Object Data Source
	    ''' </summary>
        <DataObjectMethod(DataObjectMethodType.Insert, True)> Public Sub Insert(ByVal Team1id As Integer,ByVal Team2id As Integer,ByVal Dte As DateTime,ByVal Team1score As String,ByVal Team2score As String,ByVal NewsID As Nullable(Of Integer),ByVal IsComplete As Boolean)
	   
		    Dim item As Games = New Games()
		    
            item.Team1id = Team1id
            
            item.Team2id = Team2id
            
            item.Dte = Dte
            
            item.Team1score = Team1score
            
            item.Team2score = Team2score
            
            item.NewsID = NewsID
            
            item.IsComplete = IsComplete
            
	    
		    item.Save(UserName)
	   
	   End Sub
    	
	    ''' <summary>
	    ''' Updates a record, can be used with the Object Data Source
	    ''' </summary>
        <DataObjectMethod(DataObjectMethodType.Update, True)> Public Sub Update(ByVal Id As Integer,ByVal Team1id As Integer,ByVal Team2id As Integer,ByVal Dte As DateTime,ByVal Team1score As String,ByVal Team2score As String,ByVal NewsID As Nullable(Of Integer),ByVal IsComplete As Boolean)
	    
		    Dim item As Games = New Games()
		    
				item.Id = Id
				
				item.Team1id = Team1id
				
				item.Team2id = Team2id
				
				item.Dte = Dte
				
				item.Team1score = Team1score
				
				item.Team2score = Team2score
				
				item.NewsID = NewsID
				
				item.IsComplete = IsComplete
				
		    item.MarkOld()
		    item.Save(UserName)
	    
	    End Sub
    End Class
End Namespace
